﻿var imgArray = new Array();
var imgNumb = 1;
var AnswerArray = new Array(); //Array the will contain the answers
var Answer;
var CurrentImg = 1;
var answer;

//Loop that fills the image array
for (var i = 0; i < 22; i++) {
    imgArray[i] = new Image();
    imgArray[i].src = '../Images/PRiC/PRiC_img' + imgNumb + '.jpg';
    imgNumb++;
}


//The first function that is called, removes the inoformation div and displays the images and question buttons
function nextImage() {
    document.getElementById("divImages").style.display = "";
    document.getElementById("divInformation").style.display = "none";
};

//A function that hides the textbox question and display the question with the woman
function nextImage2() {
    document.getElementById("divTextBox").style.display = "none";
    document.getElementById("divAnswers").style.display = "";
    AnswerArray[CurrentImg - 1] = $("#tbxAnswer").val();
    CurrentImg++;
};

//A function which is called if you answer yes on the woman question
function AnswerYes() {
    document.getElementById("divAnswers").style.display = "none";
    document.getElementById("divAnswerNo").style.display = "none";
    document.getElementById("divAdult").style.display = "";
    AnswerArray[CurrentImg - 1] = "";
    CurrentImg++;
    //CurrentImg++;
}

//A function which is called when you push the next button after you have answered yes on the woman question
function IfYes() {
    document.getElementById("divAnswers").style.display = "none";
    document.getElementById("divAnswerNo").style.display = "none";
    document.getElementById("divAdult").style.display = "";
    AnswerArray[CurrentImg - 1] = $("#tbxAnswer1").val();
    CurrentImg++;
}

//A function which is called if you answer no on the woman question
function AnswerNo() {
    document.getElementById("divAnswers").style.display = "none";
    document.getElementById("divAnswerNo").style.display = "";
    document.getElementById("divAdult").style.display = "none";
}

//A function which is called if you answer yes on the adult question
function AdultAnswerYes() {
    document.getElementById("divAdult").style.display = "none";
    document.getElementById("divAdultQuestions").style.display = "none";
    document.getElementById("divAdultYesQuestion").style.display = "";
}

//A function which is called when you push the next button after you have answered yes on the adult question
function IfYes2() {
    document.getElementById("divAdult").style.display = "none";
    document.getElementById("divAdultQuestions").style.display = "none";
    document.getElementById("divAdultYesQuestion").style.display = "none";
    document.getElementById("divLastAdult").style.display = "";
    AnswerArray[CurrentImg - 1] = $("#tbxAnswer2").val();
    CurrentImg++;
}

//A function which is called if you answer no on the adult question
function AdultAnswerNo() {
    document.getElementById("divAdult").style.display = "none";
    document.getElementById("divAdultQuestions").style.display = "none";
    document.getElementById("divAdultYesQuestion").style.display = "none";
    document.getElementById("divLastAdult").style.display = "";
    AnswerArray[CurrentImg - 1] = "";
    CurrentImg++;
    
}

//A functions which is called everytime you push the next question button on the 24 first questions
function nextImageButton1() {
    if (CurrentImg <= 21) {
        document.getElementById("divTextBox").style.display = "none";
        document.getElementById("divImages").style.display = "";
        document.getElementById("divInformation").style.display = "none";
        document.getElementById("divAnswers").style.display = "none";
        document.getElementById("PRiC_img01").src = imgArray[CurrentImg].src;
        hideNext();
        $('.buttonclicked').removeClass('buttonclicked').addClass('button');
        AnswerArray[CurrentImg - 1] = answer;
        CurrentImg++;
    }
    else if (CurrentImg == 22) {
        document.getElementById("divFeeling").style.display = "";
        document.getElementById("divTextBox").style.display = "none";
        document.getElementById("divImages").style.display = "none";
        document.getElementById("divInformation").style.display = "none";
        document.getElementById("divAnswers").style.display = "none";
        hideNext();
        $('.buttonclicked').removeClass('buttonclicked').addClass('button');
        AnswerArray[CurrentImg - 1] = answer;
        CurrentImg++;
    }
    else if (CurrentImg == 23) {
        document.getElementById("divFeeling").style.display = "none";
        document.getElementById("divTextBox").style.display = "";
        document.getElementById("divImages").style.display = "none";
        document.getElementById("divInformation").style.display = "none";
        document.getElementById("divAnswers").style.display = "none";
        hideNext();
        $('.buttonclicked').removeClass('buttonclicked').addClass('button');
        AnswerArray[CurrentImg - 1] = answer;
        CurrentImg++;
    }
}

//A function which i called when you answer question number 27
function nextImageButton(a){
    if (CurrentImg == 27 || CurrentImg == 26) {
        document.getElementById("divInformation").style.display = "none";
        document.getElementById("divImages").style.display = "none";
        document.getElementById("divFeeling").style.display = "none";
        document.getElementById("divTextBox").style.display = "none";
        document.getElementById("divAnswers").style.display = "none";
        document.getElementById("divAnswerNo").style.display = "none";
        document.getElementById("divAdult").style.display = "none";
        document.getElementById("divAdultQuestions").style.display = "";
        Answer = a;
        AnswerArray[CurrentImg - 1] = Answer;
        CurrentImg++;
    }
};

//A function which is called when you answear the last question, the function saves you answers in the database
function getAnswerArray() {
    AnswerArray[CurrentImg - 1] = $("#tbxAnswer3").val();

    var answers = AnswerArray;
    PageMethods.getAnswerArray(answers);
    document.getElementById("divLastAdult").style.display = "none";
    document.getElementById("divThanks").style.display = "";
    var avg = 0;
    for (var i = 0; i < 23; i++) {
        avg += parseInt(AnswerArray[i]);
    }
    //$("#answerResults").append("Ditt medelvärde är: " + Math.round(avg / 23 * 10) / 10);
}

//A function which is called when you change your answer on the first 24 questions
function change_select(objs) {

    $('.buttonclicked').removeClass('buttonclicked').addClass('button');
    objs.className = "buttonclicked";
    showNext();
    answer = objs.value.toString()[0];
}

//A function which blocks the div that contians the nextquestion button 
function showNext() {
    document.getElementById("divNextButton").style.display = "block";
    document.getElementById("divNextButton1").style.display = "block";
}

//A function which displays the div that contians the nextquestion button
function hideNext() {
    document.getElementById("divNextButton").style.display = "none";
    document.getElementById("divNextButton1").style.display = "none";
}

//A function which is called when you are done with the test, it redirects you to the main page
function done() {
    window.location = "main.aspx";
}

